import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';

import '../flutter_tracker.dart';

class QwsIconButton extends StatelessWidget {
  final uuid = const Uuid();
  final double? iconSize;
  final VisualDensity? visualDensity;
  final EdgeInsetsGeometry? padding;
  final AlignmentGeometry? alignment;
  final double? splashRadius;
  final Widget icon;
  final Color? focusColor;
  final Color? hoverColor;
  final Color? color;
  final Color? splashColor;
  final Color? highlightColor;
  final Color? disabledColor;
  final VoidCallback? onPressed;
  final MouseCursor? mouseCursor;
  final FocusNode? focusNode;
  final bool autofocus;
  final String? tooltip;
  final bool? enableFeedback;
  final BoxConstraints? constraints;
  final ButtonStyle? style;
  final bool? isSelected;
  final Widget? selectedIcon;
  final String eventId;
  final String eventType;
  final String? extraInfo;
  final bool tracker;

  const QwsIconButton({
    super.key,
    required this.eventId,
    required this.eventType,
    this.tracker = true,
    this.extraInfo,
    this.iconSize,
    this.visualDensity,
    this.padding,
    this.alignment,
    this.splashRadius,
    this.color,
    this.focusColor,
    this.hoverColor,
    this.highlightColor,
    this.splashColor,
    this.disabledColor,
    required this.onPressed,
    this.mouseCursor,
    this.focusNode,
    this.autofocus = false,
    this.tooltip,
    this.enableFeedback,
    this.constraints,
    this.style,
    this.isSelected,
    this.selectedIcon,
    required this.icon,
  });

  void press() {
    var start = DateTime.now().millisecondsSinceEpoch;
    onPressed!();
    if (tracker) {
      FlutterTracker.instance.event(
        eventId: eventId,
        eventType: eventType,
        extraInfo: extraInfo,
        traceId: uuid.v4(),
        costTime: DateTime.now().millisecondsSinceEpoch
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return IconButton(
      onPressed: press,
      icon: icon,
      iconSize: iconSize,
      visualDensity: visualDensity,
      padding: padding,
      alignment: alignment,
      splashRadius: splashRadius,
      color: color,
      focusColor: focusColor,
      hoverColor: hoverColor,
      highlightColor: highlightColor,
      disabledColor: disabledColor,
      mouseCursor: mouseCursor,
      focusNode: focusNode,
      autofocus: autofocus,
      tooltip: tooltip,
      enableFeedback: enableFeedback,
      constraints: constraints,
      style: style,
      isSelected: isSelected,
      selectedIcon: selectedIcon,
    );
  }
}
